package cn.jbolt.ec.order;

import cn.jbolt._admin.permission.CheckPermission;
import cn.jbolt._admin.permission.PermissionKey;
import cn.jbolt.base.JBoltBaseController;
import cn.jbolt.common.bean.OptionBean;
import cn.jbolt.common.model.BecRetailerOrder;
import cn.jbolt.ec.retailer.RetailerService;
import com.jfinal.aop.Inject;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Page;

import java.util.ArrayList;
import java.util.List;

@CheckPermission(PermissionKey.ORDER_AMIN)
public class EcOrderAuthController extends JBoltBaseController {

    @Inject
    OrderService orderService;

    @Inject
    RetailerService retailerService;

    /**
     * ***************************************************
     * 下面为管理端方法，主要为更新数据
     * @author heqingyu
     * *******************************************
     */


    /**
     *  后台管理 主页
     */
    @CheckPermission(PermissionKey.ORDER_INDEX)
    public void  index(){
        Page<BecRetailerOrder> becRetailerOrders =  orderService.get_retailer_order_page(getPageSize(),getPageNumber(),
                getKeywords(),getInt("retailerId"),getInt("isType"),getLong("onTime"));
        keepPara();

        set("pageData",becRetailerOrders);
        set("total_amount_total",orderService.get_order_amount_total(getKeywords(),getInt("retailerId"),getInt("isType"),getLong("onTime")));
        set("total_amount_paid",orderService.get_order_amount_paid(getKeywords(),getInt("retailerId"),getInt("isType"),getLong("onTime")));
        set("total_retailer_amount",orderService.get_order_retailer_amount(getKeywords(),getInt("retailerId"),getInt("isType"),getLong("onTime")));

        render("index.html");
    }


    /**
     * select isType下拉数据源
     */
    public void get_retailerOrder_Type(){
        List<OptionBean> options=new ArrayList<OptionBean>();
        options.add(new OptionBean("正常",1));
        options.add(new OptionBean("简易",2));
        options.add(new OptionBean("商家余额充值送卷",3));
        options.add(new OptionBean("平台余额充值",5));
        options.add(new OptionBean("全民秒杀",14));
        options.add(new OptionBean("分销商秒杀",15));
        renderJsonData(options);
    }


    /**
     * select 时间下拉数据源
     */
    public void get_retailerOrder_time(){
        List<OptionBean> options=new ArrayList<OptionBean>();
        options.add(new OptionBean("近一天记录",1));
        options.add(new OptionBean("近三天记录",3));
        options.add(new OptionBean("近十天记录",10));
        options.add(new OptionBean("近一个月记录",31));
        options.add(new OptionBean("近三个月记录",93));
        renderJsonData(options);
    }


    public void order_retailer_option(){
        renderJsonData(retailerService.getCommonList("id,name"));

    }


}
